package com.shuwen.gcdj.controller.demo;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shuwen.gcdj.common.api.CommonPage;
import com.shuwen.gcdj.common.api.CommonResult;
import com.shuwen.gcdj.common.api.ResultCode;
import com.shuwen.gcdj.common.exception.ApiException;
import com.shuwen.gcdj.bean.demo.request.Demo1QueryParam;
import com.shuwen.gcdj.bean.demo.response.Demo1QueryVO;
import com.shuwen.gcdj.common.annotation.Auth;
import com.shuwen.gcdj.entity.Demo1;
import com.shuwen.gcdj.service.demo.Demo1Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @oauth 李东旭
 * @createDate 2021/11/17
 * @info
 */
@Api(tags = "测试相关接口", description = "测试相关接口")
@Auth
@RestController
@RequestMapping("/service")
public class TestController {

    @Autowired
    private Demo1Service demo1Service;

    @ApiOperation(value = "测试数据(带分页)")
    @RequestMapping(value = "/pages", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<Demo1QueryVO>> getPages(Demo1QueryParam queryParam) {
        if(queryParam.getPageNum() == null || queryParam.getPageSize() == null){
            throw new ApiException(ResultCode.VALIDATE_FAILED);
        }
        Page<Demo1> page = new Page<>(queryParam.getPageNum(), queryParam.getPageSize());
        return demo1Service.getList(queryParam,page);
    }

    @ApiOperation(value = "测试数据(不带分页)")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<Demo1>> getList(Demo1QueryParam queryParam) {
        return CommonResult.success(demo1Service.list());
    }

}
